/*
 * @Author: szx
 * @Date: 2022-06-07 13:06:21
 * @LastEditTime: 2022-06-07 13:20:13
 * @Description:
 * @FilePath: \leetcode\800-899\875\875.js
 */
/**
 * @param {number[]} piles
 * @param {number} h
 * @return {number}
 */
var minEatingSpeed = function (piles, h) {
    let low = 1;
    let high = 0;
    high = Math.max(...piles);
    while (low < high) {
        const speed = Math.floor((high - low) / 2) + low;
        const time = piles.reduce((prev, curr) => prev + Math.ceil(curr / speed), 0);
        if (time <= h) high = speed;
        else low = speed + 1;
    }
    return high;
};
